﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PhotoOfTheDay.Types
{
    public unsafe struct Config
    {

        public Photo CurrentPhoto;
        public DateTime LastChecked;
        public bool LockOn;
        public bool ArchieveOn;
        public int WallpaperStyle;

        public void Save(string path)
        {
            byte[] buffer = new byte[sizeof(Config)];
            
            fixed (Config* data = &this)
            {
                byte* buff = (byte*)data;
                for (int i = 0; i < buffer.Length; i++)
                {
                    buffer[i] = *(buff + i);
                }
            }
            System.IO.File.WriteAllBytes(path, buffer);
        }

        public static Config Load(string path)
        {
            if (!System.IO.File.Exists(path)) return default(Config);
            byte[] buffer = System.IO.File.ReadAllBytes(path);
            if (buffer.Length != sizeof(Config)) return default(Config);
            Config config = new Config();
            fixed(byte* b = buffer)
            {
                config = *((Config*)b);
            }
            return config;
        }

        public static Config Current { get { return Global.CurrentConfig; } }

        public Wallpaper.Style Style { get { return (Wallpaper.Style)WallpaperStyle; } set { WallpaperStyle = (int)value; } }
    }
}
